﻿using interop.UIAutomationCore;
using MetroUIAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading;

namespace Win8UIAutomation
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            // initial UIA
            MetroUIA UIA = new MetroUIA();

            // start up app
            UIA.StartUp("9c8f9c5f-bad9-49f5-811f-80a1de393b0f_qv11hnzbrt7cg!App", null);

            // get the app title 'App1' and print
            IUIAutomationElement appTitle = UIA.GetElementByAutomationId("pageTitle");
            Console.WriteLine(UIA.GetElementText(appTitle));

            // wait 1 sec
            Thread.Sleep(1000);

            // find and click a list item
            IUIAutomationElement groupTitle1 = UIA.GetElementByName("Item Title: 1");
            UIA.Invoke(groupTitle1);

            // wait 1 sec
            Thread.Sleep(1000);

            // click back button
            IUIAutomationElement backBtn = UIA.GetElementByAutomationId("BackButton");
            UIA.Invoke(backBtn);

            // wait 1 sec
            Thread.Sleep(1000);

            // find and click a list item
            IUIAutomationElement itemTitle5 = UIA.GetElementByName("Item Title: 5");
            UIA.Invoke(itemTitle5);

            // wait 1 sec
            Thread.Sleep(1000);

            // click back button
            backBtn = UIA.GetElementByAutomationId("BackButton");
            UIA.Invoke(backBtn);

            // wait 1 sec
            Thread.Sleep(2000);

            // click back button
            var ControlsNav = UIA.GetElementByAutomationId("ControlsNav");
            UIA.Invoke(ControlsNav);

            // wait 1 sec
            Thread.Sleep(1000);

            UIA.Invoke(backBtn);

            // wait 1 sec
            Thread.Sleep(2000);

            // close app
            UIA.Close();
        }
    }
}
